import api from "./api";

export interface LoginRequest {
  username: string;
  captcha: string;
}

export interface LoginResponse {
  token: string;
}

/**
 * 用户登录
 * @param data 登录请求数据
 * @returns 包含 token 的响应
 */
export const login = async (data: LoginRequest): Promise<LoginResponse> => {
  const response = await api.post<LoginResponse>("/user/login", data);
  return response.data as LoginResponse;
};

/**
 * 用户登出
 * @returns 登出成功消息
 */
export const logout = async (): Promise<{ message: string }> => {
  const response = await api.post<{ message: string }>("/user/logout");
  return response.data as { message: string };
};
